package midway.madness.post.image;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;


public class MidwayGalleryAdapter extends BaseAdapter {

	private List<PictureObject> picObjs;
	private Context context;
	
	public MidwayGalleryAdapter(Context c, List<PictureObject> pPicObjs){
		context = c;
		picObjs = pPicObjs;
	}
	
	public int getCount() {
		return picObjs.size();
	}

	public Object getItem(int position) {
		return picObjs.get(position);
	}

	public long getItemId(int position) {
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		final int pos = position;
		ImageView imageView = null;
//		if (null == convertView){
			imageView = new ImageView(context);
			imageView.setImageBitmap(picObjs.get(pos).getBitmap());
			imageView.setPadding(5, 5, 5, 5);
			imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
//		}else{
//			imageView = (ImageView) convertView;
//		}
		
		imageView.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Intent intent = new Intent(context, ImageViewerActivity.class);
				intent.putExtra("url", picObjs.get(pos).getRegularUrl());
				context.startActivity(intent);
			}
		});

        return imageView;

	}
	
	public List<PictureObject> getPicObjs() {
		return picObjs;
	}
}
